#include <iostream>
#include <iomanip>
#include "equationsolver.h"
#include <limits>

const double pi = acos(-1);
const double eps = std::numeric_limits<double>::epsilon();
using namespace std;

//C题函数
double func(double x)
{
        return x - tan(x);
}

double dfunc(double x)
{
    return 1 - 1 / (cos(x) * cos(x));
}

int main()
{
    typedef double (*fp)(double);
    fp fpi = func;
    fp dfpi = dfunc;
    myfunc f(fpi,dfpi);

    newton N1(4.5,eps,100,f);
    newton N2(7.7,eps,100,f);

    cout << "Question C: " << endl;
    cout << "The Newton result near 4.5 is " << setiosflags(ios::fixed) << setprecision(2) << N1.solve() << endl;
    cout << "The Newton result near 7.7 is " << setiosflags(ios::fixed) << setprecision(2) << N2.solve() << endl;
    cout << endl;

    cout << "验证f(x1)= " << setiosflags(ios::fixed) << setprecision(2) << f(N1.solve()) << endl;
    return 0;
}